<template>
  <div class="index">
    <el-container>
      <el-header>
        <img src="../assets/logo.png" alt="" class="img1" /><span class="sp1"
          >后台管理系统</span
        >
        <el-button type="info" class="goout" @click="out()">退出</el-button>
      </el-header>

      <el-container>
        <el-aside :width="flag ? '60px' : '200px'">
          <p @click="flag = !flag">| | |</p>
          <!-- 左边菜单栏 -->
          <el-menu
            :collapse-transition="false"
            :collapse="flag"
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
          >
            <el-submenu
              :index="'' + index"
              v-for="(item, index) in List"
              :key="index"
            >
              <template slot="title">
                <i :class="icon[index]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="'/' + subitem.path"
                  v-for="subitem in item.children"
                  :key="subitem.id"
                  >{{ subitem.authName }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- // 路由占位 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { menusList } from "../utils/api";
// import {mapMutations} from 'vuex'
export default {
  data() {
    return {
      List: [],
      icon: [
        "el-icon-user-solid",
        "el-icon-s-claim",
        "el-icon-s-cooperation",
        "el-icon-s-order",
        "el-icon-s-platform",
      ],
      flag: false,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 获取index页面的数据
    async getList() {
      var res = await menusList();
      console.log(res);
      this.List = res.data.data;
    },
    // 点击退出
    out() {
      // this.$store.commit('logout')
      localStorage.removeItem("token");
      this.$router.push("/");
    },
  },
};
</script>
<style>
.el-header,
.el-footer {
  background-color: #373f41;
  color: white;
  text-align: center;
  line-height: 60px;
}

.el-aside {
 background-color: #333744;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 160px; */
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.index,
.el-container {
  width: 100%;
  height: 100%;
}
.sp1 {
  float: left;
  font-weight: 1000;
  font-size: 20px;
}
.img1 {
  width: 50px;
  height: 50px;
  float: left;
}
.goout {
  float: right;
  margin-top: 10px;
  margin-right: 50px;
}
p {
  background-color: #4a5064;
  line-height: 30px;
  color: white;
}

</style>